
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpack = require('webpack');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
  mode: "production",
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'main.js'
  },
  devServer: {
      contentBase: './dist',
      hot: true
    },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
    	template: path.join(__dirname, './src/index.html'),
    	filename: 'index.html'
    }),
    new webpack.HotModuleReplacementPlugin(),
    new VueLoaderPlugin()
    ],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
      },
      {
        test: /\.less$/,
        use: [
          {
            loader: 'style-loader', // creates style nodes from JS strings
          },
          {
            loader: 'css-loader', // translates CSS into CommonJS
          },
          {
            loader: 'less-loader', // compiles Less to CSS
          },
        ],
      },
      {
        test: /\.scss$/,
        use: [
            "style-loader", // creates style nodes from JS strings
            "css-loader", // translates CSS into CommonJS
            "sass-loader" // compiles Sass to CSS, using Node Sass by default
        ]
       },
       {
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
            },
          },
        ],
        },
        {
        test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
        use: [
           'url-loader'
        ]
        },
      {
      test: /\.m?js$/,
      exclude: /(node_modules|bower_components)/,
      use: {
        loader: 'babel-loader',
        options: {
          presets: [  "@babel/preset-env",
                      "@babel/preset-react",
                   ],
          plugins: [
                      "@babel/plugin-transform-runtime",
                      "@babel/plugin-proposal-class-properties",
                      ["component", 
                          {
                            "libraryName": "mint-ui",
                            "style": true
                          }
                      ]
                    ],
          ignore: ["./src/lib/mui/js/mui.min.js"],
        }
      }
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
    ],
  },  
  resolve: {
    alias: {
      // "vue$": "vue/dist/vue.js"
    }
  }
};